package com.cuit.blogsystem.controller.Text;

import com.cuit.blogsystem.DTO.CommentPageQueryDTO;
import com.cuit.blogsystem.DTO.TextPageQueryDTO;
import com.cuit.blogsystem.DTO.TypePageQueryDTO;
import com.cuit.blogsystem.Result.PageResult;
import com.cuit.blogsystem.Result.Result;
import com.cuit.blogsystem.VO.TextVO;
import com.cuit.blogsystem.service.CommentService;
import com.cuit.blogsystem.service.TextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/blog/text")
public class TextController {

    @Autowired
    private TextService textService;
    @Autowired
    private CommentService commentService;

    /**
     * 单篇文章查询
     */
    @GetMapping("listText/{id}")
    public Result<TextVO> listText(@PathVariable Long id){
        TextVO textVO = textService.listText(id);
        return Result.success(textVO);
    }

    /**
     * 分页查询文章
     */
    @GetMapping("/listText")
    public Result<PageResult> list(TextPageQueryDTO textPageQueryDTO){
        PageResult pageResult = textService.pageQueery(textPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 分页查询某文章下的评论
     */
    @GetMapping("/listComment")
   public Result<PageResult> list(CommentPageQueryDTO commentPageQueryDTO){
        PageResult pageResult = commentService.pageQuerry(commentPageQueryDTO);
        return Result.success(pageResult);
   }

    /**
     * 查询所有分类
     */
   @GetMapping("/listType")
   public Result<List<String>> typeList(){
        List<String> tyList  = textService.pageQueeryType();
        return Result.success(tyList);
   }
}
